package com.lingnan.tijian.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lingnan.tijian.common.annotation.Log;
import com.lingnan.tijian.common.core.controller.BaseController;
import com.lingnan.tijian.common.core.domain.AjaxResult;
import com.lingnan.tijian.common.enums.BusinessType;
import com.lingnan.tijian.domain.CheckItem;
import com.lingnan.tijian.service.ICheckItemService;
import com.lingnan.tijian.common.utils.poi.ExcelUtil;
import com.lingnan.tijian.common.core.page.TableDataInfo;

/**
 * 检查项Controller
 * 
 * @author 常熟阿诺
 * @date 2025-01-05
 */
@RestController
@RequestMapping("/tijian/checkItem")
public class CheckItemController extends BaseController
{
    @Autowired
    private ICheckItemService checkItemService;

    /**
     * 查询检查项列表
     */
    @PreAuthorize("@ss.hasPermi('tijian:checkItem:list')")
    @GetMapping("/list")
    public TableDataInfo list(CheckItem checkItem)
    {
        startPage();
        List<CheckItem> list = checkItemService.selectCheckItemList(checkItem);
        return getDataTable(list);
    }

    /**
     * 导出检查项列表
     */
    @PreAuthorize("@ss.hasPermi('tijian:checkItem:export')")
    @Log(title = "检查项", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CheckItem checkItem)
    {
        List<CheckItem> list = checkItemService.selectCheckItemList(checkItem);
        ExcelUtil<CheckItem> util = new ExcelUtil<CheckItem>(CheckItem.class);
        util.exportExcel(response, list, "检查项数据");
    }

    /**
     * 获取检查项详细信息
     */
    @PreAuthorize("@ss.hasPermi('tijian:checkItem:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(checkItemService.selectCheckItemById(id));
    }

    /**
     * 新增检查项
     */
    @PreAuthorize("@ss.hasPermi('tijian:checkItem:add')")
    @Log(title = "检查项", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CheckItem checkItem)
    {
        return toAjax(checkItemService.insertCheckItem(checkItem));
    }

    /**
     * 修改检查项
     */
    @PreAuthorize("@ss.hasPermi('tijian:checkItem:edit')")
    @Log(title = "检查项", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CheckItem checkItem)
    {
        return toAjax(checkItemService.updateCheckItem(checkItem));
    }

    /**
     * 删除检查项
     */
    @PreAuthorize("@ss.hasPermi('tijian:checkItem:remove')")
    @Log(title = "检查项", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(checkItemService.deleteCheckItemByIds(ids));
    }
}
